<template>
  <div>
    <el-breadcrumb separator-icon="ArrowRight">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>分类:{{ category_name }}</el-breadcrumb-item>
    </el-breadcrumb>
    <category-item
      class="stent"
      v-for="single in categorys"
      :key="single.article_id"
      :single="single"
    ></category-item>
  </div>
</template>

<script>
import axios from 'axios'
import CategoryItem from './components/CategoryItem.vue'
export default {
  data() {
    return {
      categorys: [],
      category_name: '',
    }
  },
  //  activated生命周期keep-alive每次切回来该组件都会触发一次
  activated() {
    // console.log('接餐' + this.$route.params.id)
    axios
      .get(`http://localhost:3001/category/${this.$route.params.id}`)
      .then((res) => {
        this.categorys = res.data.result.data
      })
    axios
      .get(`http://localhost:3001/category/only/${this.$route.params.id}`)
      .then((res) => {
        console.log(res.data.result.data.category_name) //拿到所属分类名
        this.category_name = res.data.result.data.category_name
      })
  },

  components: {
    CategoryItem,
  },
}
</script>

<style scoped>
.el-breadcrumb {
  margin-top: 10px;
  padding: 0 10px;
}
.stent {
  margin-top: 10px;
  padding: 10px 20px;
}
</style>
